<?php
/*************************************************

个人中心主模型 - the 
Author: WangHuabin <17-10-23>

*************************************************/
namespace Home\Controller;
use Think\Controller;
class PersonController extends Controller {
    //获取用户信息
    public function get_user_info(){
         $user_id = I('post.userid');
         if($user_id){
            $map['id'] = $user_id;
            $user_info = D('User')->get_one($map);

                //平台投资总额
                $starttime        =strtotime(date('Ymd',time()-86400));
                $endtime          =time();
                $map              = array();
                $map['user_id']   = $user_id;
                $plat_count       = D('UserObject')->obj_sum($map);
                $map['add_time']  = array('between',$starttime.','.$endtime);
                $today_plat_count = D('UserObject')->obj_sum($map);
                //首投返利总额
                $map                = array();
                $map['user_id']     = $user_id;
                $map['platform_id'] = array('neq',11);
                $map['type']        = 1;
               
                $map['add_time']    = array('between',$starttime.','.$endtime);
                $today_st_count     = D('Bill')->m_sum($map);

                //加息
                $map                = array();
                $map['user_id']     = $user_id;
                $map['platform_id'] = array('neq',11);
                $map['type']        = 2;
                $ft_count           = D('Bill')->m_sum($map);
                $map['add_time']    = array('between',$starttime.','.$endtime);
                $today_ft_count     = D('Bill')->m_sum($map);

                //ROI返利总额
                $map                = array();
                $map['user_id']     = $user_id;
                $map['platform_id'] = array('eq',11);
                $map['type']        = array(array('eq',1),array('eq',2), 'or');
                $roi_count          = D('Bill')->m_sum($map);
                $map['add_time']    = array('between',$starttime.','.$endtime);
                $today_roi_count    = D('Bill')->m_sum($map);

                //累计返现
                $count_fx=$st_count+$ft_count+$roi_count;
                //昨天返利额
                $today_fx_count = $today_st_count+$today_ft_count+$today_roi_count;

                //判断用户是否是推手
                if($user_info['role']==2){
                    $starttime       = strtotime(date('Y-m-d 0:0:0',time()-3600*24));
                    $map             = array();
                    $map['referral'] = $user_info['id'];
                    $map['add_time'] = array('between',$starttime.','.time());
                    $user_info['push']['today_push_user_count'] = M('UserPlatform')->where($map)->count();
                    
                    // 
                    $map = array();
                    $map['referral'] = $user_info['id'];
                    $tj_user = D('User')->get_all($map);
                       foreach ($tj_user as $k => $v) {
                            $tj_user_id[] = $v['id'];
                        }
                        if($tj_user_id){
                            $map['user_id']      = array('in',$tj_user_id);
                            $map['type']         = array('in','1,2'); //投资而不是推手返利
                            $map['add_time']     = array('between',$starttime.','.time());//今日
                            $today_tz_user_count = D('UserObject')->group_count($map);
                            $user_info['push']['today_tz_user_count'] = count($today_tz_user_count);
                        }else{
                            $user_info['push']['today_tz_user_count'] = 0;
                        }
                        $map = array();
                        $map['user_id'] =$user_id;
                         $user_info['recommend'] = D('Recommend')->get_one($map);
                }

                   //cpa cps 当日数据
                    $map['id'] = $user_id;
                    $starttime          = strtotime(date('Y-m-d 0:0:0',time()-3600*24));
                    $map['platform_id'] = array('neq',11);
                    $map['type']        = 3;
                    $cpa_push          = D('Bill')->sum($map);
                    $map['add_time']    = array('between',$starttime.','.time());
                    $cpa_today          = D('Bill')->sum($map);
                    $user_info['push']['cpa_today'] =  $cpa_today?$cpa_today:'0.00';

                    $map = array();
                    $map['id'] = $user_id;
                    $map['type'] = 4;
                    $cps_push   = D('Bill')->sum($map);
                    $map['add_time']    = array('between',$starttime.','.time());
                    $cps_today   = D('Bill')->sum($map);
                    $user_info['push']['cps_today'] = $cps_today?$cps_today:'0.00';

                    $map = array();
                    $map['user_id'] = $user_id;
                    $map['platform_id'] = array('eq',11);
                    $map['type']        = array(array('eq',3),array('eq',4), 'or');
                    $roi_push          = D('Bill')->sum($map);
                    $map['add_time']    = array('between',$starttime.','.time());
                    $roi_today          = D('Bill')->sum($map);
                    $user_info['push']['roi_today'] = $roi_today?$roi_today:'0.00';



                

         }
         if($user_info){
            $res['errorCode'] = 1;
            $res['msg'] = '成功';
            $res['data'] = $user_info;
            $res['data']['investor']['today_plat_count'] = $today_plat_count?$today_plat_count:'0.00';//今日投資
            $res['data']['investor']['plat_count'] = $plat_count?$plat_count:'0.00';;//投資總額
            $res['data']['investor']['st_count'] = $st_count?$st_count:'0.00';;//首投總額
            $res['data']['investor']['today_st_count'] = $today_st_count?$today_st_count:'0.00';;//今日首投總額
            $res['data']['investor']['ft_count'] = $ft_count?$ft_count:'0.00';;//加息總額
            $res['data']['investor']['today_ft_count'] = $today_ft_count?$today_ft_count:'0.00';;//今日加息總額
            $res['data']['investor']['roi_count'] = $roi_count?$roi_count:'0.00';;//roi總額
            $res['data']['investor']['today_roi_count'] = $today_roi_count?$today_roi_count:'0.00';;//今日roi總額
            //累计返现
            $count_fx = $st_count+$ft_count+$roi_count;
            $count_push = $roi_push+$cps_push+$cpa_push;
            $res['data']['investor']['count_fx']=$count_fx?$count_fx:'0.00';
            $res['data']['investor']['count_push']=$count_push?$count_push:'0.00';
                //昨天返利额
            $today_fx_count =  $today_st_count+$today_ft_count+$today_roi_count;
            $res['data']['investor']['today_fx_count'] = $today_fx_count?$today_fx_count:'0.00';

         }else{
               $res['errorCode'] = 0;
                $res['msg'] = '未查询到数据';
         }
         $this->ajaxReturn($res);
    }

    //獲取綁定的平台
    public function get_bind_plat(){
        $user_id = I('post.userid');
        if($user_id){
            //平台数据
            $map = array();
            $map['user_id'] = $user_id;
            $plat_bing_count = M('UserPlatform')->where($map)->count();
            $tz_count = M('UserObject')->where($map)->field('count(*)')->group('platform_id')->select();
            $tz_count= count($tz_count);

            //绑定平台列表
            $page = 1;
            $pagenum = 10;
            $list_platform_list = D('UserPlatform')->where($map)->limit(($page-1)*$pagenum,$pagenum)->select();
            $page_count = D('UserPlatform')->where($map)->count();
            $page_num = ceil($page_count/10);
        
            foreach ($list_platform_list as $k => $v) {
                $platform_id = $v['platform_id'];
                $map = array();
            //    $map['id'] = $platform_id;
                $map['_string'] ='id = '.$platform_id.' and id <>2 ';
                $platform_list[$k] = D('Platform')->get_one($map);
                $platform_list[$k]['bing_time'] = $v['add_time'];
            }
            if($platform_list){
                foreach ($platform_list as $k => $v) {
                    //投资标的数
                    $map = array();
                    $map['platform_id'] = $v['id'];
                    $map['user_id'] = $user_id;
                    $obj_count= D('UserObject')->count($map);
                    if(!$obj_count){
                         $platform_list[$k]['obj_count'] = '0';
                    }else{
                         $platform_list[$k]['obj_count'] = $obj_count;
                    }
                    //投资总额
                    $map = array();
                    $map['user_id'] = $user_id;
                    $map['platform_id'] = $v['id'];
                    $plat_count = D('UserObject')->obj_sum($map);
                    if(!$obj_count){
                         $platform_list[$k]['plat_count'] = '0.00';
                    }else{
                         $platform_list[$k]['plat_count'] = $plat_count;
                    }

                    $pic = $v['pic'];
                    $platform_list[$k]['pic'] = preg_replace ('/http:\/\//', 'https://', $pic,1);

                    //返利总额
                    $map = array();
                    $map['user_id'] = $user_id;
                    $map['type'] = array('in','1,2');
                    $map['platform_id'] = $v['id'];
                    $fl_count = D('Bill')->m_sum($map);
                    if(!$obj_count){
                         $platform_list[$k]['fl_count'] = '0.00';
                    }else{
                         $platform_list[$k]['fl_count'] = $fl_count;
                    }

                }
            }
            if($platform_list){
                $res['errorCode'] = 1;
                $res['msg'] = "获取成功";
                $res['data'] = $platform_list;
            }
            $this->ajaxReturn($res);
        }
    }

    //获取用户站内信
    public function get_msg(){
        $user_id = I('post.userid');
        $page = I('post.page',1,int);
        $pageSize = I('post.pageSize',10,int);
        if($user_id) {
            $map = array();
            $map['user_id'] = $user_id;
            $message = D('Message')-> get_all($map,$field='*',$page,$pageSize);
            $map = array();
            $map['id'] = $user_id;
            $user = D('User')->get_one($map);
            $map = array();
            foreach($message as $k => $v) {
                $map['id'] = $v['type_id'];
                $mes_type = D('MessageType')->get_one($map);
                $message[$k]['type_id'] = $mes_type['type'];
                $message[$k]['message_date'] = date('Y-m-d',$v['add_time']);
                $message[$k]['message_time'] = date('H:i:s',$v['add_time']);
                if($v['is_read']==0) {
                    $unread[] = $v['is_read'];
                }
                $message[$k]['nickname'] = $user['nickname'];
            }
            if($message){
                $res['errorCode'] = 1;
                $res['msg'] = "获取成功";
                $res['data'] = $message;
            }else{
                $res['errorCode'] = 0;
                $res['msg'] = "暂无数据";
            }
            $this->ajaxReturn($res);
        }
    }


    //站内信详情设置站内信为已读
     public function message_info() {
          $user_id = I('post.userid');
        if($user_id) {
            $mes_id = I('get.id');
            $map['id'] = $mes_id;
            $news = D('Message')->get_one($map);
            $news['notice_date'] = date('Y-m-d',$news['add_time']);
            $news['notice_time'] = date('H:i:s',$news['add_time']);
            $map = array();
            $map['id'] = $user_id;
            $user = D('User')->get_one($map);
            $news['nickname'] = $user['nickname'];
            $map = array();
            $map['user_id'] = $user_id;
            $map['id'] = $mes_id;
            if($news) {
                $data['is_read'] = 1;
                D('Message')->edit($map,$data);
            }
            if($news){
                $res['errorCode'] = 1;
                $res['msg'] = "获取成功";
                $res['data'] = $news;
            }else{
                $res['errorCode'] = 0;
                $res['msg'] = "暂无数据";
            }
        }
        $this->ajaxReturn($res);
    }



    //获取公告信息
    public function get_notice(){
        $user_id = I('post.userid');
        $page = I('post.page',1,int);
        $pageSize = I('post.pageSize',10,int);
        if($user_id) {
                $map['id'] = $user_id;
                $user = D('User')->get_one($map);
                $map = array();
                $cate_id = 39;
                $map['cate_id'] = $cate_id;
                $field = "*";
                $order = "add_time asc";
                $news = D('NewsHouse')->get_all_page($map,$field="id,title,content_short,add_time",$order,($page-1)*$pageSize,$pageSize);
                $new_count = D('NewsHouse')->count($map);
            //    print_r($new_count);
                foreach($news as $k => $v) {
                    $news[$k]['notice_date'] = date('Y-m-d',$v['add_time']);
                    $news[$k]['notice_time'] = date('H:i:s',$v['add_time']);
                    $news_id[] = $v['id'];
                    $news[$k]['nickname'] = $user['nickname'];
                }
                $map = array();
                $map['user_id'] = $user_id;
                $new_notice = D('NewsNotice')->where($map)->select();
                $notice_new = D('NewsNotice')->where($map)->count();
            //    print_r($notice_new);
                foreach ($news as $k => $v) {
                    $id = $v['id'];
                    foreach ($new_notice as $ke => $va) {
                        $news_id = $va['news_id'];
                        if($news_id==$id){
                            $news[$k]['is_read'] = 1;
                            break;
                        }else{
                            $news[$k]['is_read'] = 0;
                        }
                    }
                }
                $notice_read = $new_count-$notice_new;
                if($notice_read>0) {
                    //存在未读
                    $notice_reads = 1;
                } else {
                    $notice_reads = 0;
                }
        }

            if($news){
                $res['errorCode'] = 1;
                $res['msg'] = "获取成功";
                $res['data'] = $news;
                $res['notice_reads']= $notice_reads;
            }else{
                $res['errorCode'] = 0;
                $res['msg'] = "暂无数据";
            }
            $this->ajaxReturn($res);
    }

    //公告详情
    public function notice_details() {
          $user_id = I('post.userid');
        if($user_id) {
            $news_id = I('get.news_id');
            $map['id'] = $news_id;
            $news = D('NewsHouse')->get_one($map);
            $news['notice_date'] = date('Y-m-d',$news['add_time']);
            $news['notice_time'] = date('H:i:s',$news['add_time']);
            $map = array();
            $map['id'] = $user_id;
            $user = D('User')->get_one($map);
            $news['nickname'] = $user['nickname'];
            if($news) {
                $data['news_id'] = $news['id'];
                $data['user_id'] = $user_id;
                $map = array();
                $map['news_id'] = $news['id'];
                $map['user_id'] = $user_id;
                $newnotice = M('NewsNotice')->where($map)->find();
                if(!$newnotice){
                    M('NewsNotice')->add($data);
                }
            }
             if($news){
                $res['errorCode'] = 1;
                $res['msg'] = "获取成功";
                $res['data'] = $news;
            }else{
                $res['errorCode'] = 0;
                $res['msg'] = "暂无数据";
            }
            $this->ajaxReturn($res);
        }
    }


    //修改用戶暱稱
    public function change_nickname(){
            $nickname = I('post.nickname');
            $userid = I('post.userid');
            $map['id'] = $userid;
           // echo $_SESSION['user']['id'];die;
            $data['nickname'] = $nickname;
            $r = D('User')->edit($map,$data);
           // echo D('User')->_sql();die;
            if($r){
                    $_SESSION['user']['nickname'] = $nickname;
                    $data = array('errorCode'=>1,'msg'=>"修改成功！");
            }else{
                    $data = array('errorCode'=>2,'msg'=>"修改失败！");
            }
                $this->ajaxReturn($data);

        
    }

     //修改登錄密碼
    public function change_password(){

            $new_password = I('post.new_password');
            $old_password = I('post.old_password');
            $userid = I('post.userid');
            $map['id'] = $userid;
            $user_info = D('User')->get_one($map);
            $user_mixs = $user_info['user_mixs'];
           // echo $user_mixs;die;
            //echo $user_info['user_pass']."***".md5($old_password.$user_mixs);die;
            $old_password = md5($old_password.$user_mixs);
            if($old_password == $user_info['user_pass']){

                $data['user_pass'] = md5($new_password.$user_mixs);
                $r = D('User')->edit($map,$data);
                if($r){
                    $data = array('errorCode'=>1,'msg'=>"修改成功");
                }else{
                    $data = array('errorCode'=>2,'msg'=>"修改失败");
                }


            }else{
                $data = array('errorCode'=>3,'msg'=>"原密码错误！");
            }
            $this->ajaxReturn($data);
    }
    //实名
    public function realname(){

        $realname = I('post.realname');
        $idcard = I('post.idcard');
        $userid = I('post.userid');
        $map['id'] = $userid;
        $user = D('User')->get_one($map);
        if($user['idcards']) {
            $data = array(
                    'errorCode' => 8,
                    'msg' => "您已实名认证"
                );
                 $this->ajaxReturn($data);
                
        }
        $map = array();
        $map['idcard'] = $idcard;
        $idcards = D('User')->get_one($map);
        if($idcards) {
            $data = array(
                    'errorCode' => 8,
                    'msg' => "身份证已被绑定"
                );
                 $this->ajaxReturn($data);
                
        }


         if(empty($realname)) {
            $data = array(
                'errorCode' => 7,
                'msg' => "名字不能为空"
            );
                $this->ajaxReturn($data);
            
        }
        if(empty($idcard)) {
            $data = array(
                'errorCode' => 8,
                'msg' => "身份证号码不能为空"
            );
                $this->ajaxReturn($data);
            
        }
        $map['user_id'] = $userid;
        $re = M('Realname')->where($map)->find();
        if($re){
                $add_day = date('ymd',$re['add_time']);
                $num = $re['num'];
                $today = date('ymd',time());
                    if($num>=5){
                        if($today==$add_day){
                            $data = array(
                                'errorCode' => 4,
                                'msg' => "今天验证次数已经超过5次！明天再来！"
                            );
                        }else{
                            //验证
                            $data =$this->get_real($idcard,$realname);
                            if($data['errorCode']!=3){
                                $arr_data = array('num'=>1,'add_time'=>time());
                                $map['id'] = $re['id'];
                                $r = M('Realname')->where($re['id'])->save($arr_data);
                            }
                            
                        }
                    }else{
                            $num = $num+1;
                            $number = 5-$num;
                            $data =$this->get_real($idcard,$realname,$userid,$number);
                            if($data['errorCode']!=3){
                                $arr_data = array('num'=>$num,'add_time'=>time());
                                $map['id'] = $re['id'];
                                $r = M('Realname')->where($re['id'])->save($arr_data);
                            }
                            
                    }

        }else{
                        $data = $this->get_real($idcard,$realname,$userid);
                        if($data['errorCode']!=3){
                            $arr_data = array('num'=>1,'add_time'=>time(),'user_id'=>$userid);
                            $r = M('Realname')->data($arr_data)->add();
                        }
        }
                        $this->ajaxReturn($data);
        

    }



    public function get_real($idcard,$realname,$userid,$number='4'){
         $real =R('Real/v_real',array($idcard,$realname));
    //     print_r($real);die;
    //    $real =Array ( 'reason' => '成功', 'result' => Array ( 'realname' => '王华斌', 'idcard'=>'362427199205230819', 'res'=> 1 ), 'error_code'=> 0 );
        //    $real = '{"reason":"\u6210\u529f","result":{"realname":"\u738b\u534e\u658c","idcard":"362427199205230819","res":1},"error_code":0}';
     
        if($real){
            if($real['error_code']=='0') {

               if($real['result']['res']==1){
                $data = array(
                    'errorCode' => 1,
                    'msg' => "验证成功！"
                );
                //写入用户数据
                $id = $userid;
                $map['id'] = $id;
                $arr_data = array(
                    'realname' => $realname,
                    'idcard'   => $idcard,
                    'card_status' => 1
                );
                $user =D('User')->edit($map,$arr_data);
                //echo D('User')->_sql();die;
                //實名成功發送消息
                R('Msg/sendmail',array($typename='realname',$userid = $id));
            //    $_SESSION['user']['realname'] = $realname;
            //    $_SESSION['user']['idcard'] = $idcard;
            //    $_SESSION['user']['card_status'] = 1;
               }else{
                     $data = array(
                        'errorCode' => 2,
                        'msg' => "验证失败，还剩".$number."次机会"
                    );
               }
            } else {
                $data = array(
                    'errorCode' => 3,
                    'msg' =>"信息填写有误！"
                );
            }
        }else{
                    $data = array(
                        'errorCode' => 3,
                        'msg' => "验证请求失败！"
                    );
        }
            return($data);


    }


     //绑定银行卡
    public function bind_bank() {
        $postdata = I('post.');
        $user_id = I('post.userid');
        $map=array();
        $map['id'] = $user_id;
        $user = D('User')->get_one($map);
        if($user['bank_card']){
            $data = array('errorCode'=>3,'msg'=>"您已绑定银行卡，请解绑后再试");
             $this->ajaxReturn($data);
        }
        if($user['card_status']==0) {
            $data = array('errorCode'=>3,'msg'=>"未实名认证，请先实名验证");
        } else {
            $s = trim($postdata['bank_card']);
            $bank_phone = trim($postdata['bank_phone']);
                //验证手机号
            if(strlen($bank_phone)!=11 || !preg_match( '/^1[3|4|5|7|8][0-9]\d{4,8}$/',$bank_phone)) {
                $data = array('errorCode'=>5,'msg'=>"手机号有误");
            } else {
                // $luhm = $this->luhm($s);
                $luhm['errorCode']=0;
                if($luhm['errorCode']==0){
                    $time = time();
                    $today = date('Y-m-d',$time);
                    $firstday = strtotime($today);
                    $tomorrow = date('Y-m-d',strtotime( "+1 day",$time));
                    $lastday = strtotime($tomorrow);
                    $map['user_id'] = $user['id'];
                    $map['add_time'] = array('between',"$firstday,$lastday");
                    $bank_info = M('Bank')->where($map)->count();
                    if($bank_info<5) {
                        //绑定银行卡
                        //$bank =  R('Bankcard/get_card_info',array($user['realname'],$user['idcard'],$s,$bank_phone));
                        //测试数据  : 王华斌    362427199205230819    6212264000004496036    18079792115
                        //$bank =  R('Bankcard/get_card_info',array("王华斌","362427199205230819","6212264000004496036","15099835829"));
                           $bank = Array(
                                    'code' => 10000,
                                    'message' => '成功',
                                    'data' => Array
                                        (
                                            'state' => 1
                                        ),

                                    'seqNo' => 'OT2379551708151459'
                                    );
                        //    print_r($bank);
                        $ba['code'] = $bank['code'];
                        $ba['message'] = $bank['message'];
                        $ba['state'] = $bank['data']['state'];
                        $ba['seqno'] = $bank['seqNo'];
                        $ba['add_time'] = time();
                        $ba['user_id'] = $user['id'];
                        $ban = M('Bank')->add($ba);
                        //调用接口成功时做判断
                            if($bank['code']==10000 && $bank['data']['state']==1) {
                                $map['id'] = $user['id'];
                                $data['bank_card'] = $postdata['bank_card'];
                                $res = D('User')->edit($map,$data);
                                if($res) {
                                    $_SESSION['user']['bank_card'] = $data['bank_card'];
                                    R('Msg/sendmail',array($typename='bind_bank',$userid = $user['id']));
                                    $data = array('errorCode'=>1,'msg'=>"添加银行卡成功");
                                } else {
                                    $data = array('errorCode'=>7,'msg'=>"添加银行卡失败");
                                }
                            } else {
                                $data = array('errorCode'=>4,'msg'=>"银行卡信息有误");
                            }
                    } else {
                        $data = array('errorCode'=>6,'msg'=>"一天只限绑定5次银行卡");
                    }

                }else{
                    $data = array('errorCode'=>2,'msg'=>"银行卡填写错误");
                }
            }

        }
        $this->ajaxReturn($data);
    }


    //解绑银行卡
    public function unbind_bank_msg(){
        $userid = I('post.userid');
        $idcard = I('post.idcard');
        $map['id'] = $userid;
        $map['idcard'] = $idcard;
        $r = D('User')->get_one($map);
         if($r){
             $phone = $r['user_phone'];
             $map = array();
             $startday = strtotime(date('Y-m-d 0:0:0',time()));
             $map['add_time'] = array('gt',$startday);
             $map['phone'] = $phone;
             $msgcount = C('MSG_COUNT_USER');
             $ip = get_client_ip_user();
             $count = D("Verification")->count($map);

                 if($count>=$msgcount){
                     $data = array('errorCode'=>2,'msg'=>"验证码发送次数过多,请明天再试！");
                     $this->ajaxReturn($data);
                 }else{
                     $map = array();
                     $map['phone'] = $phone;
                     $map['status'] =0;
                     $map['role'] =6;
                     $r = D("Verification")->get_one($map);
                     if($r['add_time']<=(time()-60)){
                         //发送验证码
                         $code = rand(111111,999999);
                         $res = R('Send/sendsms',array($phone,$code,$type = 1));
                         if($res['err']==0){
                             //记录短信发送
                            $msgdata['type']=1;
                            $msgdata['role']=6;
                            $msgdata['phone']=$phone;
                            $msgdata['status']=0;
                            $msgdata['add_time']=time();
                            $msgdata['time_failure']=time()+300;
                            $msgdata['code']=$code;
                            $msgdata['ip']=$ip;
                            $res = D("Verification")->add($msgdata);
                                if($res){
                                    unset($_SESSION['is_idcard']);
                                    $data = array('errorCode'=>1,'msg'=>"发送成功！");
                                    $this->ajaxReturn($data);
                                }else{
                                    $data = array('errorCode'=>5,'msg'=>"发送失败！");
                                    $this->ajaxReturn($data);
                                }
                        }else{
                                $data = array('errorCode'=>6,'msg'=>"发送失败，接口异常！");
                                $this->ajaxReturn($data);
                        }
                    }else{
                        $data = array('errorCode'=>4,'msg'=>"发送频率过快，休息一会！");
                        $this->ajaxReturn($data);
                    }
                 }
            

         }else{
             $data = array('errorCode'=>7,'msg'=>"未找到用户！");
             $this->ajaxReturn($data);
         }
    }

    //銀行卡解綁
    public function un_bind_bank(){

        $userid = I('post.userid');
        $map['id'] = $userid;
        $r = D('User')->get_one($map);
        $phone = $r['user_phone'];
        $map = array();
        $map['phone'] = $phone;
        $map['status'] =0;
        $map['role'] =6;
        $v_msg= D("Verification")->get_one($map);
        if($v_msg){
            $code = I('post.code');
            $time_failure = $v_msg['time_failure'];
            if($time_failure<time()){
                $data = array('errorCode'=>2,'msg'=>"到验证码已过期！");
            }else{
                $v_code = $v_msg['code'];
                if($code==$v_code){
                    //解绑
                    $datas['bank_card'] = '';
                    $map = array();
                    $map['id'] = $userid;
                    $r = D('User')->edit($map,$datas);
                    $map = array();
                    $map['phone'] = $phone;
                    $arr['status'] = 1;
                    $res = D('Verification')->edit($map,$arr);
                    if($r){
                         $data = array('errorCode'=>1,'msg'=>"解绑成功");
                    }else{
                         $data = array('errorCode'=>4,'msg'=>"解绑失败");
                    }
                }else{
                    $data = array('errorCode'=>3,'msg'=>"验证码错误");
                }
            }
        }else{
            $data = array('errorCode'=>5,'msg'=>"未找到验证码！");
        }
        $this->ajaxReturn($data);

    }


    //修改手機號碼（旧号码）
    public function change_phone(){

            $code = I('post.code');
            $map['phone'] =I('post.phone');
            $map['status'] = 0;
            $map['role'] = 3;
            $codeinfo = D('Verification')->get_one($map);

            if($codeinfo){
                if($codeinfo['code']==$code && $codeinfo['status']==0){
                    if($codeinfo['time_failure']<=time()){
                        $data = array('errorCode'=>2,'msg'=>'验证码已过期！');
                    }else{
                        $data = array('errorCode'=>1,'msg'=>'验证成功！','code_id'=>$codeinfo['id']);
                    }
                }else{
                    $data = array('errorCode'=>3,'msg'=>'验证码错误！');
                }
            }else{
                    $data = array('errorCode'=>4,'msg'=>'验证码无效！');
            }

            $this->ajaxReturn($data);
        
    }

       //提交新手机号码完成手机号码修改
    public function change_phone_end(){
       if(IS_POST){
        $phone = I('post.phone');
        $code = I('post.code');

        $old_phone = I('post.old_phone');
        $code_id = I('post.code_id');
        $userid = I('post.userid');

        $map['status'] = 0;
        $map['phone'] = $phone;
        $map['role'] =3;
        $codeinfo = D('Verification')->get_one($map);
        if($codeinfo){
                if($codeinfo['code']==$code && $codeinfo['status']==0){
                    if($codeinfo['time_failure']<=time()){
                        $data = array('errorCode'=>1,'msg'=>'验证码已过期！');
                    }else{
                        //验证码正确
                    $map = array();
                    $data = array();
                    $map['id'] = $userid;
                    $data['user_phone'] = $phone;
                    $r = D('User')->edit($map,$data);

                    if($r){                       
                        $map = array();
                        $map['id'] = $code_id;
                        $data_arr['status'] = 1;
                        $data = D("Verification")->edit($map,$data_arr);
                        $data = array('errorCode'=>1,'msg'=>'成功！');
                    }else{
                        $data = array('errorCode'=>4,'msg'=>'失败！');
                    }                    

                    }
                }else{
                    $data = array('errorCode'=>3,'msg'=>'验证码错误！');
                }
            }else{
                    $data = array('errorCode'=>2,'msg'=>'验证码无效！');
            }
            $this->ajaxReturn($data);

        }else{
        $this->display();

        }
    }

    //头像修改
    public function change_head_pic(){
            $user_pic = I('post.file');
            $userid = I('post.userid');
            if($user_pic){
                 $res = R('Upload/index',array($user_pic));
                 $data['url_img'] = $res['url'];
            }
            $map['id'] =$userid;
             $r = D('User')->edit($map,$data);
            if($r){
                $this->ajaxReturn(array('errorCode'=>1,'msg'=>"修改成功","url"=>$res['url']));
            }else{
                 $this->ajaxReturn(array('errorCode'=>0,'msg'=>"修改失败"));
            }
    }


    //获取手续费
    public function get_deduction(){
        $id = I('post.userid');
        $map = array();
        $firstday = strtotime(date('Y-m-d'),time());
        $lastday = strtotime(date('Y-m-d',strtotime('+1 day')));
        $map['add_time']=array('between',"$firstday,$lastday");
        $map['user_id'] = $id;
        $num = D('Cash')->where($map)->count();
        if($num>=1) {
            $deduction = 1;
            $data = array('errorCode'=>1,'msg'=>"提现收取手续费1元");
        } else{
            $deduction = 0;
            $data = array('errorCode'=>2,'msg'=>"每天首次提现免手续费");
        }
        $this->ajaxReturn($data);
    }
     //提现
    
    public function withdrawals() {
    
            //校验用户是否实名认证
            $id =I('post.userid');
            $map['id'] = $id;
            $u = D('User')->get_one($map);
            //验证绑定身份证
            if($u['card_status']==1 && !empty($u['idcard'])) {
            //校验用户是否绑定银行卡
                if(!empty($u['bank_card'])) {
                //判断提现金大于50元才能提
                    $affirmdepo = I('post.affirmdepo');
                    $type = I('post.type');
                    if(is_numeric($affirmdepo)) {
                        //判断是否为推手
                        if($type==2) {
                                if($affirmdepo>=50) {
                                    if($affirmdepo<=$u['prize_balance']) {
                                            $data =  $this->cash_do($id,$affirmdepo,$type);
                                    } else {
                                            $data = array('errorCode'=>4,'msg'=>"您的可提金额不足，前往投资拿更多返利");
                                    }
                                } else {
                                    $data = array('errorCode'=>3,'msg'=>"提现金额需大于50元");
                                }
                        //不是推手1元起提
                        } else {
                                if($affirmdepo>1) {

                                    if($affirmdepo<=$u['balance']) {
                                         $data = $this->cash_do($id,$affirmdepo,$type);
                                    } else {
                                            $data = array('errorCode'=>4,'msg'=>"您的可提金额不足，前往投资拿更多返利");
                                    }
                                } else {
                                    $data = array('errorCode'=>3,'msg'=>"提现金额需大于1元");
                                }

                        }


                    } else {
                        $data = array('errorCode'=>9,'msg'=>"请输入提现金额");
                    }
                 } else {
                     $data = array('errorCode'=>2,'msg'=>"您还未绑定银行卡，请前往绑定银行卡！");
                 }
            } else {
                $data = array('errorCode'=>10,'msg'=>"完成实名认证后就可以提现哦，请前往实名认证！");
            }
        
        $this->ajaxReturn($data);
    }

    //提现操作
    public function cash_do($id,$affirmdepo,$type){
        //判断一天一次免手续费
        $map = array();
        $firstday = strtotime(date('Y-m-d'),time());
        $lastday = strtotime(date('Y-m-d',strtotime('+1 day')));
        $map['add_time']=array('between',"$firstday,$lastday");
        $map['user_id'] = $id;
        $num = D('Cash')->where($map)->count();
        if($num>=1) {
            $deduction = 1;
            $data = array('errorCode'=>6,'msg'=>"提现收取手续费1元");
        } else{
            $deduction = 0;
            $data = array('errorCode'=>5,'msg'=>"每天首次提现免手续费");
        }
        $sursums = $affirmdepo-$deduction;//已扣除手续费
        $datas['user_id'] = $id;
        $datas['amount'] = $sursums;//提现金额
        $datas['fee'] = $deduction;//手续费
        $datas['add_time'] = time();//添加时间
        $res = D('Cash')->add($datas);
        if($res) {
            $data = array('errorCode'=>1,'msg'=>"发起提现");
            $dat['user_id'] = $id;
            $dat['quota'] = $sursums;
            $dat['deduction'] = $deduction;
            $dat['add_time'] = time();//添加时间
            $dat['status'] = 1;
            $dat['remarks'] = "用户发起资金提现";
            $map = array();
            $map['id'] = $id;
            $user_info = D('User')->get_one($map);

            if($type==1){
                $balance = $user_info['balance'];
            }else{
                $balance = $user_info['prize_balance'];
            }

            $quota = $sursums+$deduction;

            if($type==1){
                D('User')->balance($map,$quota);
            }else{
                D('User')->prize_balance($map,$quota);
            }

            $balance =$balance-$quota;
            $dat['balance'] = $balance;
            $dat['tx_type'] = $type;
            $ress = D('Bill')->add($dat);
            $phone = $u['user_phone'];
            $date = date('Y年m月d日 H时i分',time());
            $money = $sursums+$deduction;
            $send = R('Send/cash_apply',array($phone,$date,$money,$deduction));
            R('Msg/sendmail',array($typename='affirmdepo',$userid = $id));
        }else {
            $data = array('errorCode'=>8,'msg'=>"提现失败，参数有误");
            
        }
        return $data;
        

    }


    //账单明细
    public function trade_details() {
        $user_id = I('post.userid');
        $type = I('post.type');
        $page = I('post.page',1,int);
        $pageSize = I('post.pageSize',10,int);
        if($type==1){
            $map['type'] =array('in','1,3');
        }else if($type==2){
             $map['type'] =array('in','2,4');
        }else if($type==3){
            $map['type'] =5;
        }
        $map['user_id'] = $user_id;
        $bill = D('Bill')->get_all_page($map,($page-1)*$pageSize,$pageSize);
            foreach($bill as $k => $v) {
                $bill[$k]['notice_date'] = date('Y-m-d',$v['add_time']);
                $bill[$k]['notice_time'] = date('H:i:s',$v['add_time']);
                if($v['type']==1) {
                    $bill[$k]['type'] = "首投返利（用户）";
                } elseif($v['type']==2) {
                    $bill[$k]['type'] = "加息返利（用户）";
                } elseif($v['type']==3) {
                    $bill[$k]['type'] = "首投返利（投顾）";
                } elseif($v['type']==4) {
                    $bill[$k]['type'] = "加息返利（投顾）";
                } elseif($v['status']==1) {
                    $bill[$k]['type'] = "用户提现";
                }
            }
            if($bill){
                $res['errorCode'] = 1;
                $res['msg'] = "获取成功";
                $res['data'] = $bill;
            }else{
                $res['errorCode'] = 0;
                $res['msg'] = "暂无数据";
            }
            $this->ajaxReturn($res);
           
    }


    //账单详情
    public function trade_details_info() {
        $user_id =I('get.userid');
        if($user_id){
            $id = I('get.id');
            $map['id'] = $id;
            $bill = D('Bill')->get_one($map);
                if($bill['type']==1) {
                    $bill['type'] = "首投返利（用户）";
                } elseif($bill['type']==2) {
                    $bill['type'] = "加息返利（用户）";
                } elseif($bill['type']==3) {
                    $bill['type'] = "首投返利（投顾）";
                } elseif($bill['type']==4) {
                    $bill['type'] = "加息返利（投顾）";
                } elseif($bill['status']==1) {
                    $bill['type'] = "用户提现";
                }
                $bill['add_time'] = date('Y-m-d H:i:s',$bill['add_time']);
                $fl_user_id = $bill['fl_user_id'];
                $map = array();
                if($fl_user_id){
                    $map['id'] = $fl_user_id;
                    $fl = D('User')->get_one($map);
                }
                $bill['remark'] =$fl['nickname'].$bill['type'];
                if($bill){
                    $res['errorCode'] = 1;
                    $res['msg'] = "获取成功";
                    $res['data'] = $bill;
                }else{
                    $res['errorCode'] = 0;
                    $res['msg'] = "暂无数据";
                }
                $this->ajaxReturn($res);
           
        }
    }

        //自动提现开关
    public function auto_cash(){
        $auto = I('post.auto');
        $userid = I('post.userid');
        $map['id'] = $userid;
        $user = D('User')->get_one($map);
        if($auto==1){
            $bank_card = $user['bank_card'];
            if($bank_card){
                $map=array();
                $map['id'] = $userid;
                $data['auto_cash'] = 1;
                $r = D('User')->edit($map,$data);
                if($r){
                    $data = array('errorCode'=>1,'msg'=>"自动提现已开启！");
                }else{
                    $data = array('errorCode'=>2,'msg'=>"自动提现开启失败！");
                }
            }else{
                $data = array('errorCode'=>3,'msg'=>"您还未绑定银行卡正在前往安全中心！");
            }
        }else{
            $map=array();
            $map['id'] =$userid;
            $data['auto_cash'] = 0;
            $r = D('User')->edit($map,$data);
            if($r){
                $data = array('errorCode'=>1,'msg'=>"自动提现已关闭！");
            }else{
                $data = array('errorCode'=>4,'msg'=>"自动提现关闭失败！");
            }
        }
        $this->ajaxReturn($data);
    }


    //合作平台
    public function push_plat_list(){
        $userid = I('post.userid');
        $hz_plat_info = $this->hz_platinfo($userid);
        //print_r($hz_plat_info);die;
        foreach ($hz_plat_info as $k => $v) {
            $pic = $v['pic'];
            $hz_plat_info[$k]['pic'] = preg_replace ('/http:\/\//', 'https://', $pic,1);
            $plat_id = $v['id'];
            $map['platform_id'] = $plat_id;
            $scheme = D('PlatformScheme')->get_all($map);
            
            foreach ($scheme as $ke => $va) {
                $scheme[$ke]['is_get'] = 1;
            }
            $hz_plat_info[$k]['scheme'] = $scheme;
            
           // echo D('PlatformScheme')->_sql();die;
        }
       // print_r($hz_plat_info);die;
        $un_plat_list = $this->un_hz_plat($userid);
       // print_r($un_plat_list);die;
        foreach ($un_plat_list as $k => $v) {
            $pic = $v['pic'];
            $un_plat_list[$k]['pic'] = preg_replace ('/http:\/\//', 'https://', $pic,1);
            $map['platform_id'] = $v['id'];
            // echo $id;
            $unscheme= D('PlatformScheme')->get_all($map);
            if($unscheme){
                $un_plat_list[$k]['scheme'] = $unscheme;
                foreach ($unscheme as $ke => $va) {
                    $un_plat_list[$k]['scheme'][$ke]['is_get'] = 0;
                }
            }
           // 
        }

        if(!$hz_plat_info){
            $hz_plat_info = array();
        }
        if(!$un_plat_list){
            $un_plat_list = array();
        }

        $plat_list = array('team'=>array_values($hz_plat_info),'not_team'=>$un_plat_list);
        if($hz_plat_info or $un_plat_list){
                $res['errorCode'] = 1;
                $res['msg'] = "获取成功";
                $res['data'] = $plat_list;
        }else{
            $res['errorCode'] = 0;
            $res['msg'] = "暂无数据";
        }

        $this->ajaxReturn($res);
    }


       //合作平台投资明细
    public function hz_platinfo($user_id,$platform_name='',$starttime='',$endtime=''){
        // $user_id = 444;
        //合作平台
        $map['user_id'] = $user_id;
        $recommend = D('Recommend')->get_one($map);
        $map['recommend_id'] = $recommend['id'];
        $map['status'] = 1;
        if($starttime && $endtime){
            $map['add_time'] = array('between',$starttime.','.$endtime);
        }
        $r_plat = D('RecommendPlatform')->get_all($map);
       //print_r($r_plat);
        // echo D('RecommendPlatform')->_sql();
        if($r_plat){
            //合作平台id集合
            foreach ($r_plat as $k => $v) {
                $platform_id[] = $v['platform_id'];
            }
             //平台注册用户
            $map = array();
            $map['referral'] = $user_id;
            $u_list =M('User')->where($map)->select();
           
            if($u_list){
                foreach ($u_list as $key => $value) {
                $u_plat_user_id[]=$value['id'];
                }
            }
            $map['platform_id'] = array('in',$platform_id);
            $u_plat =M('UserPlatform')->where($map)->select();
     
            //合作平台投资明细
            foreach($r_plat as $k=>$v){
                $platform_id = $v['platform_id'];
                $map = array();
                $map['id'] = $platform_id;

                if($platform_name){
                    $map['name'] = array('like', '%'.$platform_name.'%'); ;
                }
                $field = "`id`,`name`,`user_award`,`rebate`,`user_roi`,`pic`,`team_type`";
                $platform_info= D('Platform')->get_one($map,$field);
                if($platform_info){
                   // $r_plat[$k]['platform_info'] = $platform_info;
                    $r_plat[$k]= $platform_info;
                    if($platform_info['coo_end_date']>=time()){
                        $r_plat[$k]['coo_status'] = "推广期";
                    }else{
                        $r_plat[$k]['coo_status'] = "返利期";
                    }
                    
                }else{
                    unset($r_plat[$k]);
                }
             //  return ($u_plat);
                if($u_plat){
                    //平台注册总数
                    if($u_plat_user_id){
                        $where['user_id'] = array('in',$u_plat_user_id);
                        $where['platform_id'] = $v['platform_id'];
                        $u_plat_count =M('UserPlatform')->where($where)->count();
                        $map = array();
                        $map['user_id'] = array('in',$u_plat_user_id);
                        $map['platform_id'] = $v['platform_id'];
                        $group = 'user_id';
                        $tj_list = D('UserObject')->group_count($map,$group);  

                    }else{
                        $u_plat_count=0;
                        $tj_list=0;
                    }
                  
                    
                    //查询平台投资人数
                    $r_plat[$k]['tj_list_count'] = count($tj_list); //平台投资人数
                    if($u_plat_count){
                        $un_tz_count = $u_plat_count-count($tj_list); //已注册为投资人数
                        if($un_tz_count>=0){
                            $r_plat[$k]['un_tz_count'] = $un_tz_count; //已注册为投资人数
                        }else{
                            $r_plat[$k]['un_tz_count'] =0;
                        }
                    }
                    //首投返利金额
                    $map = array();
                    $map['user_id'] = $user_id;
                    $map['type'] = 3;
                    $map['platform_id'] = $v['platform_id'];
                    $plat_st_count = D('Bill')->m_sum($map);
                    $r_plat[$k]['plat_st_count'] = $plat_st_count?$plat_st_count:'0.00';
                    //复投返利金额
                    $map['type'] = 4;
                    $plat_ft_count= D('Bill')->m_sum($map);
                    $r_plat[$k]['plat_ft_count'] = $plat_ft_count?$plat_ft_count:'0.00';
                    //总投资额
                    if($u_plat_user_id){
                        $map = array();
                        $map['platform_id'] = $v['platform_id'];
                        $map['user_id'] = array('in',$u_plat_user_id);
                        $tz_count = D('UserObject')->obj_sum($map);  
                        $r_plat[$k]['count_tz'] =$tz_count;
                    }else{
                        $r_plat[$k]['count_tz'] =0;
                    }
                   
                    //平台总收益
                    $map = array();
                    $map['user_id'] = $user_id;
                    $map['platform_id'] = $v['platform_id'];
                    $map['type'] =array('in','3,4');
                    $r_plat[$k]['plat_profit'] = D('Bill')->m_sum($map);
                    $r_plat[$k]['plat_st_count'] = $plat_st_count;

                }else{
                    if($platform_info){
                        $r_plat[$k]['tj_list_count'] =0;
                        $r_plat[$k]['un_tz_count'] =0;
                        $r_plat[$k]['plat_st_count'] = 0;
                        $r_plat[$k]['plat_ft_count'] = 0;
                        $r_plat[$k]['count_tz'] = 0;
                        $r_plat[$k]['plat_profit']=0;
                    }
                    
                }
                
                
                
            }

            

        }else{
            $r_plat = '';
        }

        return $r_plat;
    }

    //未合作平台
    public function un_hz_plat($user_id){
        $map['user_id'] = $user_id;
        $recommend = D('Recommend')->get_one($map);
        $map['recommend_id'] = $recommend['id'];
        $map['status'] = 1;
        $r_plat = D('RecommendPlatform')->get_all($map);
        if($r_plat){
            //合作平台id集合
            foreach ($r_plat as $k => $v) {
                $platform_id[] = $v['platform_id'];
            }
            $map['status'] = 0;
            $map['id'] =array('not in',$platform_id);
            $field = "`id`,`name`,`user_award`,`rebate`,`user_roi`,`pic`,`team_type`";
            $platform_list = D('Platform')->get_all($map,$field);
        }else{
            $map['status'] = 0;
            $field = "`id`,`name`,`user_award`,`rebate`,`user_roi`,`pic`,`team_type`"; 
            $platform_list = D('Platform')->get_all($map,$field);
            //return $platform_list;
        }
        foreach($platform_list as $k=>$v){
            $platform_id = $v['id'];
            $map = array();
            $map['platform_id'] = $platform_id;
            $map['recommend_id'] =  $recommend['id'];
            $map['status'] = 0;//申请中
            $r = D('RecommendPlatform')->get_one($map);
            if($r){
                $platform_list[$k]['is_apply'] = 1;
            }else{
                $platform_list[$k]['is_apply'] = 0;
            }
        }
        return $platform_list;
    }




    //推手專區
    public function push_list(){
        //查詢推手信息
        $id = I('post.userid');
        $page = I('post.page',1,int);
        $pageSize = I('post.pageSize',10,int);
        $map['user_id'] = $id;
        $recommend = D('Recommend')->get_one($map);

        if($recommend){

             //查詢所有平台
            $map = array();
            $map['status'] = 0;
            $platform = D('Platform')->get_all_page($map,($page-1)*$pageSize,$pageSize,$order='`order` asc');
            foreach ($platform as $k => $v) {
               $platform_id = $v['id'];
               //查詢該平台是否被認領
               $map=array();
               $map['recommend_id'] = $recommend['id'];
               $map['platform_id'] = $platform_id;
               $r = D('RecommendPlatform')->get_one($map);

               //echo D('RecommendPlatform')->_sql();
               if($r){
                    $platform[$k]['is_get'] = 1;
               }else{
                    $platform[$k]['is_get'] = 0;
               }

                $pic = $v['pic'];
                $platform[$k]['pic'] = preg_replace ('/http:\/\//', 'https://', $pic,1);
            }

            if($platform){
                $res['errorCode'] = 1;
                $res['msg'] = "获取成功";
                $res['data'] = $platform;
            }else{
                $res['errorCode'] = 0;
                $res['msg'] = "暂无数据";
            }
        }else{
            $res['errorCode'] = 2;
            $res['msg'] = "您不是推手";
        }
       
        $this->ajaxReturn($res);
    }



    //我的投資人
    
    public function investor(){
        $userid = I('post.userid');
        $page = I('post.page');
        $pageSize = I('post.pageSize');
        $map['referral'] =$userid;
        $user_count =  D('User')->count($map); //总推广用户数
        $user_push_list =  D('User')->get_all($map); //总推广用户数
        foreach($user_push_list as $k=>$v){
            $user_id_push[] = $v['id'];
        }

        $user_id_push_count = count($user_id_push);
        if($user_id_push){
             $map = array();
             $map['user_id'] = array('in',$user_id_push);
             $u_obj = D('UserObject')->group_count($map); //投资用户
            $u_list = D('UserObject')->get_all_group($map,$group="user_id",$field='*',$page,$pageSize); //投资用户
             foreach($u_list as $k=>$v){
                $u_list_id[] = $v['user_id'];
             }
            if($u_list){
                foreach($u_list as $k=>$v){
                    $u_list_id[] = $v['user_id'];
                }
                 if($u_list_id){
                    $map['id'] = array('not in',$u_list_id);
                    $map['referral'] =$userid;
                    $un_obj = D('User')->where($map)->limit($page,$pageSize)->select(); //投资用户
                    //echo  D('User')->_sql();

                 }else{
                    $un_obj ='';
                 }
             }else{
                $map['id'] = array('in',$user_id_push);
                $map['referral'] =$userid;
                $un_obj = D('User')->where($map)->limit($page,$pageSize)->select();
             }
              
             foreach ($un_obj as $k => $v) {
                $map = array();
                $map['user_id'] = $v['id'];
                $userplat = D('UserPlatform')->where($map)->find(); //投资用户
                $un_obj[$k]['userplat'] = $userplat;

                $map = array();
                $map['id_user'] =$v['id'];
                $user_info_detail= D('UserInfo')->get_one($map);
                $un_obj[$k]['user_info_detail'] = $user_info_detail;
                if($userplat){
                    $t_s = $user_info_detail['add_time'] - $userplat['add_time'];
                    if($t_s<10){
                        $un_obj[$k]['is_plat_reg'] = 1;
                    }else{
                         $un_obj[$k]['is_plat_reg'] = 0;
                    }
                }else{
                         $un_obj[$k]['is_plat_reg'] = 0;
                }
                
                $map = array(); 
                $map['id'] =$userplat['platform_id'];
                $platform_info = D('Platform')->get_one($map);
                $un_obj[$k]['platform_name'] = $platform_info['name'];

             }

             foreach($u_list as $k=>$v){
                $user_id = $v['user_id'];
                $map = array();
                $map['user_id'] = $user_id;
                $u_list[$k]['invest_num'] = D('UserObject')->obj_sum($map);  //累计投资
                //echo D('UserObject')->_sql();
                // 用户信息
                $map = array();
                $map['id'] = $user_id;
                $u_list[$k]['user_info'] = D('User')->get_one($map);
                $map = array();
                $map['id_user'] = $user_id;
                $u_list[$k]['user_info_detail'] = D('UserInfo')->get_one($map);
                $map = array();
                $map['id'] =$v['platform_id'];
                $platform_info = D('Platform')->get_one($map);
                $u_list[$k]['platform_name'] = $platform_info['name'];
                //用户首投加息
                $map = array();
                $map['user_id'] = $user_id;
                $map['type'] = 1;
                $user_st =  D('Bill')->m_sum($map);
                $u_list[$k]['user_st'] =$user_st?$user_st:"0.00";


                //用户复投加息
                $map = array();
                $map['user_id'] = $user_id;
                $map['type'] = 2;
                $user_ft =  D('Bill')->m_sum($map);
                $u_list[$k]['user_ft'] =$user_ft?$user_ft:"0.00";


                 //推手首投加息
                $map = array();
                $map['fl_user_id'] = $user_id;
                $map['type'] = 3;
                $push_st =  D('Bill')->m_sum($map);
                $u_list[$k]['push_st'] =$push_st?$push_st:"0.00";

                //推手复投加息
                $map = array();
                $map['fl_user_id'] = $user_id;
                $map['type'] =4;
                $push_ft =  D('Bill')->m_sum($map);
                $u_list[$k]['push_ft'] =$push_ft?$push_ft:"0.00";

            }
         }
         $list = array('u_list'=>$u_list,'un_obj'=>$un_obj);
         if($list){
                $res['errorCode'] = 1;
                $res['msg'] = "获取成功";
                $res['data'] = $list;
         }else{
            $res['errorCode'] = 0;
            $res['msg'] = "暂无数据";

         }
         $this->ajaxReturn($res);
    }
    
    //投資人明細
    public function investor_detail(){
        $data = I('get.data');
        $val = I('get.val');
        $data = unserialize(base64_decode($data));
        $data['tz_plat'] = urldecode($data['tz_plat']);
        $data['reg_plat'] = urldecode($data['reg_plat']);
        $this->assign('val',$val);
        $this->assign('data',$data);
        $this->display();
    }




  /**************************************************************************************************************************************/
  /**
   * [ajax_get_trend 获取动态]
   * @return [type] [description]
   */
 public function ajax_get_trend(){

        $userid = I('post.userid');
        $is_self = I('post.is_self');
        $self_id = I('post.self_id');
        $trend = $this->get_trend($userid,$is_self,$self_id);
       // print_r($trend);
        $val = I('post.val',5,int);
        $p = I('post.currentPage');
        $pagenum = I('post.pageSize',5,int);
        $p = ($p-1)*$pagenum;
        if($val==2){
            //点赞
            $type_arr =array('14','15','16','17');
        }elseif($val==1){
            //回复
            $type_arr =array('10','11','12','13');
            
        }elseif($val==3){
            //关注
             $type_arr =array('8','9');
        }
            foreach ($trend as $k => $v) {
               if($val==4){
                if(!$is_self){
                    $arr[] = $v;
                }
               }elseif($val==5){
                    $arr[] = $v;
               }else{
                if(in_array($v['type_id'],$type_arr)){
                    $arr[] = $v;
                }
               }
                
            }
           // print_r($arr);
            $arr=array_slice($arr,$p,$pagenum);
            if($arr){
                $res['errorCode'] = 1;
                $res['msg'] ='成功';
                $res['data'] = $arr;
            }else{
                
                $res['errorCode'] = 0;
                $res['msg'] ='无数据';
            }
            $this->ajaxReturn($res);
        
        

       
    }
    /**
     * [get_trend 获取动态]
     * @param  [type] $userid  [用户id]
     * @param  [type] $is_self [身份标识]
     * @return [type]          [description]
     */
    public function get_trend($userid,$is_self,$self_id){
        //查询关注的用户
        $map['user_id'] = $userid;
        $recommend = D('Recommend')->get_one($map);
        $map = array();
        if($recommend){
            $map['_string'] = 'recommend_id='.$recommend['id'].' OR user_id='.$userid;
            $map['status'] = 1;
        }else{
            $map['user_id'] = $userid;
            $map['status'] = 1;
        }
        $r_list = D('AdviserFollow')->where($map)->select();
        if($r_list){
            foreach ($r_list as $k => $v) {
                $map = array();
                $map['id'] = $v['recommend_id'];
                $u = D('Recommend')->get_one($map);
                $user_arr[] = $u['user_id'];
            }
        }
        $user_arr[] = $userid;
        //短评
        if($is_self){
            $map = array();
            $map['user_id'] = array('in',$user_arr);
        }else{
            $map = array();
            $map['user_id'] = $userid;
        }
        $stor_comment = D('PlatformCommentary')->get_all($map);

        foreach ($stor_comment as $k => $v) {
           $stor_comment[$k]['url'] = "/Home/Circle/commentary_info/id/".$v['id'];
           $stor_comment[$k]['tage'] = "短评";
           $stor_comment[$k]['type'] = 1;
           $where['id'] = $v['platform_id'];
           $plat_info = D('Platform')->get_one($where);
           $stor_comment[$k]['platname'] = $plat_info['name'];
           $maps['id'] = $v['user_id'];
           $stor_comment[$k]['user'] = D('User')->get_one($maps);
           $stor_comment[$k]['tag'] = explode(',',$v['tag']);

            if($self_id){
                    $stor_comment[$k]['is_praise'] = $this->praise_is($self_id,6,$v['id']);
            }else{
                    $stor_comment[$k]['is_praise'] = 0;
            }

        }//print_r($stor_comment);
        //die;
        //信批
        $announce = D('CircleAnnounce')->get_all($map);
        foreach ($announce as $k => $v) {
           $announce[$k]['url'] = "/Home/Circle/infoann_info/id/".$v['id'];
           $announce[$k]['type'] = 2;
           $announce[$k]['tage'] = "信批解读";
           $where['id'] = $v['platform_id'];
           $plat_info = D('Platform')->get_one($where);
           $announce[$k]['platname'] = $plat_info['name'];
           $maps['id'] = $v['user_id'];
           $announce[$k]['user'] = D('User')->get_one($maps);

           if($self_id){
                    $announce[$k]['is_praise'] = $this->praise_is($self_id,9,$v['id']);
            }else{
                    $announce[$k]['is_praise'] = 0;
            }
        }

        //舆情
        $opinion = D('CircleOpinion')->get_all($map);
        foreach ($opinion as $k => $v) {
           $opinion[$k]['url'] = "/Home/Circle/circle_opinion_info/id/".$v['id'];
           $opinion[$k]['type'] = 3;
           $opinion[$k]['tage'] = "舆情解读";
           $where['id'] = $v['platform_id'];
           $plat_info = D('Platform')->get_one($where);
           $opinion[$k]['platname'] = $plat_info['name'];
           $maps['id'] = $v['user_id'];
           $opinion[$k]['user'] = D('User')->get_one($maps);
           if($self_id){
                    $opinion[$k]['is_praise'] = $this->praise_is($self_id,8,$v['id']);
            }else{
                    $opinion[$k]['is_praise'] = 0;
            }
        }

        //深度
        $depth = D('Depth')->get_all($map);
        foreach ($depth as $k => $v) {
           $depth[$k]['url'] = "/Home/Circle/depth_info/id/".$v['id'];
           $depth[$k]['type'] = 4;
           $depth[$k]['tage'] = "深度评测";
           $where['id'] = $v['platform_id'];
           $plat_info = D('Platform')->get_one($where);
           $depth[$k]['platname'] = $plat_info['name'];
           $maps['id'] = $v['user_id'];
           $depth[$k]['user'] = D('User')->get_one($maps);
           if($self_id){
                    $depth[$k]['is_praise'] = $this->praise_is($self_id,7,$v['id']);
            }else{
                    $depth[$k]['is_praise'] = 0;
            }
        }
         $arr = array_merge($stor_comment,$announce,$opinion,$depth);
         //print_r($arr);
         foreach ($arr as $k => $v) {
             $user = $v['user_id'];
             $map_s['user_id'] = $user;
             $map_s['platform_id'] = $v['platform_id'];
             $arr[$k]['grade'] = D('PlatformGrade')->get_one($map_s);
         }
        if($is_self==1){
            //如果是自己进入主页还要合并站内消息
            $map['user_id'] = $userid;
            $map['type_id'] = array('in','7,8,9,10,11,12,13,14,15,16,17');
            $msg = D('Message')->get_all($map);
            foreach ($msg as $k => $v) {
                    $where['id'] =$v['t_user_id'];
                    $msg[$k]['user']  = D('User')->get_one($where);
                if($v['type_id'] == 10 or $v['type_id'] == 17){
                    //h回复 点赞为 短评
                    $maps['id'] = $v['t_id'];
                    $con = D('PlatformCommentary')->get_one($maps);
                    if($self_id){
                        $con['is_praise'] = $this->praise_is($self_id,3,$v['id']);
                    }else{
                        $con['is_praise'] = 0;
                    }
                    $msg[$k]['info'] = $con;
                    $msg[$k]['info']['tage'] = "短评";
                    $wheres['id'] = $con['platform_id'];
                    $plat_info = D('Platform')->get_one($wheres);
                    $msg[$k]['info']['platname'] = $plat_info['name'];

                    $msg[$k]['url'] = "/Home/Circle/commentary_info/id/".$con['id'];
                    $msg[$k]['type'] = 5;
                //    print_r($msg[$k]['info']);die;
                }elseif($v['type_id'] == 11 or $v['type_id'] == 14){
                    //h回复 点赞为 深度
                    
                    $maps['id'] = $v['t_id'];
                    $con = D('Depth')->get_one($maps);
                    $msg[$k]['info'] = $con;
                    $msg[$k]['info']['tage'] = "深度测评";
                    $wheres['id'] = $con['platform_id'];
                    $plat_info = D('Platform')->get_one($wheres);
                    $msg[$k]['info']['platname'] = $plat_info['name'];

                    $msg[$k]['url'] = "/Home/Circle/depth_info/id/".$con['id'];
                    $msg[$k]['type'] = 6;
                }elseif($v['type_id'] == 12 or $v['type_id'] == 15){
                    //h回复 点赞为 舆情
                    $maps['id'] = $v['t_id'];
                    $con = D('CircleOpinion')->get_one($maps);
                    $msg[$k]['info'] = $con;
                    $msg[$k]['info']['tage'] = "舆情解读";
                    $wheres['id'] = $con['platform_id'];
                    $plat_info = D('Platform')->get_one($wheres);
                    $msg[$k]['info']['platname'] = $plat_info['name'];

                    $msg[$k]['url'] = "/Home/Circle/circle_opinion_info/id/".$con['id'];
                    $msg[$k]['type'] = 7;
                }elseif($v['type_id'] == 13 or $v['type_id'] == 16){
                    //h回复 点赞为 信批
                    $maps['id'] = $v['t_id'];
                    $con = D('CircleAnnounce')->get_one($maps);
                    $msg[$k]['info'] = $con;
                    
                    $msg[$k]['info']['tage'] = "信批解读";
                    $wheres['id'] = $con['platform_id'];
                    $plat_info = D('Platform')->get_one($wheres);
                    $msg[$k]['info']['platname'] = $plat_info['name'];
                    $msg[$k]['url'] = "/Home/Circle/infoann_info/id/".$con['id'];
                    $msg[$k]['type'] = 8; 
                }elseif($v['type_id'] == 8){
                    //拜师
                    $msg[$k]['type'] = 9;
                }elseif($v['type_id'] == 9){
                    //拜师
                    $msg[$k]['type'] = 10;
                }

                if($v['type_id'] == 10 or $v['type_id'] == 11 or $v['type_id'] == 12 or $v['type_id'] == 13){
                    $commentid = $v['comment_id'];
                    $map = array();
                    $map['id'] = $commentid;
                    $comment_info = D('Comment')->get_one($map);
                    $msg[$k]['comment_count'] = $comment_info['content'];
                    $msg[$k]['comment_praise'] = $comment_info['praise_count'];

                    if($self_id){
                        $msg[$k]['is_praise'] = $this->praise_is($self_id,3,$v['comment_id']);
                    }else{
                        $msg[$k]['is_praise'] = 0;
                    }

                }
            }
            //print_r($msg);
            

             $arr = array_merge($arr,$msg);
        }

        foreach ($arr as $k => $v) {
            $add_date = $v['add_time'];
            $month = ceil(date('m',$add_date));
            $month_str='一月,二月,三月,四月,五月,六月,七月,八月,九月,十月,十一月,十二月';  
            $arr_m=explode(',',$month_str);
            foreach($arr_m as $key=>$val){  
            if($key+1==$month){  
                $arr[$k]['zh_data_m']= $val;  
                $arr[$k]['m']= date('y-m-d',$add_date);  
                }  
            }  
      
        }
       
        return($arr);
    }

     /**
     * 判断点赞
     */
    
    public function praise_is($userid,$type,$id){
        $where['id_user'] = $userid;
        $where['type'] = $type;
        $where['id_target'] = $id;
        $praise = D('Praise')->get_one($where);
        if($praise){
            $is_praise = 1;
        }else{
            $is_praise = 0;
        }
        return $is_praise;

    }


     /**
     * [get_friends 获取好友列表]
     * @return [type] [description]
     */
    public function get_friends(){
        $userid  =  I('post.userid');
        $nickname  =  I('post.nickname');
        $img  =  I('post.img');
        $list = R('Im/firend_list',array('userid'=>$userid,'nickname'=>$nickname,'img'=>$img));
        //print_r($list);die;
        //获取最后一天聊天记录
        $chat_count = 0;
        foreach ($list as $k => $v) {
            if($v['type']==1){
                $map = array();
                $map['_string'] = "send_id =".$v['user_info']['id']." or receive_id = ".$v['user_info']['id'];
            }else{
                $map = array();
                $map['group_id'] = $v['group_info']['id'];
            }
            $chat = D('Chat')->where($map)->order('add_time desc')->find();
            if($chat){
                $list[$k]['lats_chat'] = $chat;
                $list[$k]['lats_chat']['content'] = msubstr($chat['content'], 0, 20, $charset="utf-8", $suffix=true) ;
            }else{
                $list[$k]['lats_chat']['content']='暂无新消息';
            }
           $chat_count = $chat_count+$v['is_noread_count'];
        }

        $sort = array(  
        'direction' => 'SORT_DESC', //排序顺序标志 SORT_DESC 降序；SORT_ASC 升序  
        'field'     => 'is_noread_count',       //排序字段  
        ); 

         $arrSort = array();  
        foreach($list AS $uniqid => $row){  
            foreach($row AS $key=>$value){  
                $arrSort[$key][$uniqid] = $value;  
            }  
        }  
        if($sort['direction']){  
            array_multisort($arrSort[$sort['field']],constant($sort['direction']),$list);  
        }  
        if($list){
            $res['errorCode'] = 1;
            $res['msg'] ='成功';
            $res['data'] = $list;
        }else{
            $res['errorCode'] = 0;
            $res['msg'] ='无数据';
        }
        $this->ajaxReturn($res);

        
    }

      //推手编辑网贷信息
    public function edit_profile() {

            $user_id = I('post.userid');
        //    print_r($user_id);die;
            if($user_id) {
                $map['user_id'] = $user_id;
                $recom = D('Recommend')->get_one($map);
                if($recom) {
                    $postdata['platform_num'] = I('post.platform_num');
                    $postdata['year'] = I('post.year');
                    $postdata['pit_num'] = I('post.pit_num');
                    $postdata['introduce'] = I('post.introduce');
                    $map = array();
                    $map['id'] = $recom['id'];
                    $data = D('Recommend')->edit($map,$postdata);
                    if($data) {
                        $res = array('errorCode'=>1,'msg'=>"提交成功");
                    } else {
                        $res = array('errorCode'=>0,'msg'=>"提交失败");
                    }
                } else {
                    $res = array('errorCode'=>3,'msg'=>"您不是投顾");
                }
            } else {
                $res = array('errorCode'=>2,'msg'=>"请先登录");
            }
            $this->ajaxReturn($res);

    }

    //投顾基础信息
    public function recom_info() {
        if(IS_POST) {
            $recommend_id = I('post.id');
            $userid = I('post.userid');
            if($recommend_id) {
                $map['id'] = $recommend_id;
                $recom = D('Recommend')->get_one($map);
                $map = array();
                $map['id'] = $recom['user_id'];
                $recom['user'] = D('User')->get_one($map);
                //统计徒弟数量
                $where = array();
                $where['referral'] = $recom['user_id'];
                $recom['fans_count']=D('User')->count($where);
                if($recom) {
                    $res = array('errorCode'=>1,'msg'=>"获取成功",'data'=>$recom);
                } else {
                    $res = array('errorCode'=>0,'msg'=>"暂无数据");
                }
            } elseif($userid) {
                $map['id'] = $userid;
                $user = D('User')->get_one($map,$field='id,score,role');
                if($user['role']==2) {
                    $map = array();
                    $map['user_id'] = $user['id'];
                    $recom = D('Recommend')->get_one($map);
                    $user['recom'] = $recom;
                }
                if($user) {
                    $res = array('errorCode'=>1,'msg'=>"获取成功",'data'=>$user);
                } else {
                    $res = array('errorCode'=>0,'msg'=>"暂无数据");
                }
            }
            $this->ajaxReturn($res);
        }
    }


    //投顾红包金额列表
    public function recom_packet() {
        if(IS_POST) {
                $map = array();
                $map['status']=0;
                $platform_list= D('Platform')->get_all($map);
                $map = array();
                foreach ($platform_list as $k => $v) {
                    $map['platform_id'] = $v['id'];
                    $platform_scheme = D('PlatformScheme')->where($map)->select();
                    //查询红包价格
                    foreach ($platform_scheme as $ke => $va) {
                       $scheme_id = $va['id'];
                       $map = array();
                       $map['user_id'] = I('post.userid');
                       $map['scheme_id'] = $scheme_id;
                       $redpacket = D('RedPacket')->get_one($map);

                       if($redpacket){
                            $platform_scheme[$ke]['p_user_award'] = $redpacket['user_award'];
                            $platform_scheme[$ke]['p_push_award'] = $redpacket['push_award'];
                       }else{
                            $platform_scheme[$ke]['p_user_award'] = $va['user_award'];
                            $platform_scheme[$ke]['p_push_award'] = $va['push_award'];
                       }
                    }
                    $platform_list[$k]['scheme'] = $platform_scheme;
                    $platform_list[$k]['colligate'] = R('Circle/get_cricel_leve',array('platform_id'=>$v['id']));
                //    $platform_list[$k]['colligate'] = $colligate;
                }
            if($platform_list) {
                $data = array('errorCode'=>1,'msg'=>"获取成功！",'data'=>$platform_list);
            } else {
                $data = array('errorCode'=>0,'msg'=>"暂无数据！");
            }
            $this->ajaxReturn($data);
        }
    }


    /******************
    ****2018-3-21新增举报功能模块******
    ******************/
    public function report() {
        $user_id = I('post.userid');
        if($user_id) {
            $option = I('post.');
            $option['option'] = implode(',',$option['option']);
            $option['user_id'] = $user_id;
            $option['add_time'] = time();
            $report = M('Report')->data($option)->add();
            if($report) {
                $data = array('errorCode'=>1,'msg'=>"举报成功",'data'=>$report);
            } else {
                $data = array('errorCode'=>0,'msg'=>"举报失败");
            }
        } else {
            $data = array('err'=>2);
        }
        $this->ajaxReturn($data);

    }


    //2018-3-21新改版加入圈子详情
    public function my_circle() {
        //头部加入所有圈子列表
        $map['status'] = 0;
        $map['id'] = array('not in','2,5,7');
        $plat = D('Platform')->get_all($map,$field="id,name,wx_square_logo");
        $plats = $plat[0];
        //单个圈子动态详情
        $map = array();
        $id = I('get.id');
        if(!$id) {
            $id = $plats['id'];
        }
        $map['id'] = $id;
        $plat_name = D('Platform')->get_one($map,$field="id,name");
        //$page=0;
        //$pagenum=5;
        $map = array();
        $map['status'] = 1;
        $map['platform_id'] = $id;
        $pcomm = D('PlatformCommentary')->get_all_page($map);
        $userid = $_SESSION['user']['id'];
        $map['status'] = 1;
        $opinion = D('CircleOpinion')->get_all($map);
        foreach ($opinion as $k => $v) {
            $v['type']=4;
            $pcomm[]= $v;
        }
        $map = array();
        foreach ($pcomm as $k => $v) {
            if($v['type']!=4){
                $v['tag'] = explode(',',$v['tag']);
                $v['type']=1;
            }

            $map['id'] = $v['user_id'];
            $v['user'] =D('User')->get_one($map);
            $map = array();
            $map['user_id'] = $v['user_id'];
            $map['platform_id'] = $v['platform_id'];
            $v['grade'] = D('PlatformGrade')->get_one($map);

            $add_time = $v['add_time'];
            //判断是否点赞
            if($userid){
                $where['id_user'] = $userid;
                if($v['type']==4){
                     $where['type'] =8;
                }else{
                     $where['type'] = 6;
                }

                $where['id_target'] = $v['id'];
                $praise = D('Praise')->get_one($where);
                if($praise){
                    $v['is_praise'] = 1;
                }else{
                    $v['is_praise'] = 0;
                }
            }else{
                    $v['is_praise'] = 0;
            }
            $long = time()-$add_time;

            if($long<60){
                $v['add_date'] = $long."秒前";
            }else if($long<3600){
                $v['add_date'] = ceil($long/60)."分钟前";
            }else if($long>3600 && $long<86400){
                $v['add_date'] = ceil($long/3600)."小时前";
            }else if($long>86400 && $long<259200){
                $v['add_date'] = ceil($long/86400)."天前";
            }else if($long>259200){
                $v['add_date'] = date('Y-m-d H:i:s',$add_time);
            }else if($long=0){
                 $v['add_date'] = "刚刚";
            }
            $push_evaluate[]= $v;

        }
        //print_r($pcomm);die;
        //合并推手的深度评测
        $map = array();
        $map['platform_id'] = $id;
        $map['status'] = 1;
        $depth = D('Depth')->get_all($map);
        foreach ($depth as $k => $v) {
            $v['type']=2;
             if($userid){
                $where['id_user'] = $userid;
                $where['type'] = 7;
                $where['id_target'] = $v['id'];
                $praise = D('Praise')->get_one($where);
                if($praise){
                    $v['is_praise'] = 1;
                }else{
                    $v['is_praise'] = 0;
                }
            }else{
                    $v['is_praise'] = 0;
            }
            $map = array();
            $map['user_id'] = $v['user_id'];
            $map['platform_id'] = $v['platform_id'];
            $v['grade'] = D('PlatformGrade')->get_one($map);
            $push_evaluate[]= $v;

        }
        //合并信批
        $map = array();
        $map['platform_id'] = $id;
        $map['status'] = 1;
        $announce = D('CircleAnnounce')->get_all($map);
        foreach ($announce as $k => $v) {
            $v['type']=3;
            if($userid){
                $where['id_user'] = $userid;
                $where['type'] = 9;
                $where['id_target'] = $v['id'];
                $praise = D('Praise')->get_one($where);
                if($praise){
                    $v['is_praise'] = 1;
                }else{
                    $v['is_praise'] = 0;
                }
            }else{
                    $v['is_praise'] = 0;
            }
            $map = array();
            $map['user_id'] = $v['user_id'];
            $map['platform_id'] = $v['platform_id'];
            $v['grade'] = D('PlatformGrade')->get_one($map);
            $push_evaluate[]= $v;

        }
        foreach ($push_evaluate as $k => $v) {
            $map = array();
            $map['id'] = $v['user_id'];
            $push_evaluate[$k]['user'] =D('User')->get_one($map);
            $add_time = $v['add_time'];
            $long = time()-$add_time;
            if($long<60){
                $push_evaluate[$k]['add_date'] = $long."秒前";
            }else if($long<3600){
                $push_evaluate[$k]['add_date'] = ceil($long/60)."分钟前";
            }else if($long>3600 && $long<86400){
                $push_evaluate[$k]['add_date'] = ceil($long/3600)."小时前";
            }else if($long>86400 && $long<259200){
                $push_evaluate[$k]['add_date'] = ceil($long/86400)."天前";
            }else if($long>259200){
                $push_evaluate[$k]['add_date'] = date('Y-m-d H:i:s',$add_time);
            }else if($long=0){
                $push_evaluate[$k]['add_date'] = "刚刚";
            }
        }
        //print_r($push_evaluate);die;
        $sort = array(
        'direction' => 'SORT_DESC', //排序顺序标志 SORT_DESC 降序；SORT_ASC 升序
        'field'     => 'add_time',       //排序字段
        );

        $arrSort = array();
        foreach($push_evaluate AS $uniqid => $row){
            foreach($row AS $key=>$value){
                $arrSort[$key][$uniqid] = $value;
            }
        }
        if($sort['direction']){
            array_multisort($arrSort[$sort['field']],constant($sort['direction']),$push_evaluate);
        }
        $push_evaluate=array_slice($push_evaluate,$page,$pagenum);
        //print_r($push_evaluate);
        //$this->assign('id',$id);//平台id
        //$this->assign('plat_name',$plat_name);
        //$this->assign('push_evaluate',$push_evaluate);
        //$this->assign('plat',$plat);
        if($push_evaluate) {
            $data = array('errorCode'=>1,'msg'=>"获取成功",'data'=>array('plat_name'=>$plat_name,'plat'=>$plat,'push_evaluate'=>$push_evaluate));
        } else {
            $data = array('errorCode'=>0,'msg'=>"暂无数据",'data'=>array('plat_name'=>$plat_name,'plat'=>$plat));
        }
        $this->ajaxReturn($data);
    }



}